const { MongoClient } = require('mongodb');

async function checkDoctorCount() {
  const uri = 'mongodb://localhost:27017';
  const client = new MongoClient(uri);

  try {
    await client.connect();
    const db = client.db('cosmetic_surgery');
    
    console.log('🔍 检查医生数据数量...\n');
    
    // 获取所有医生数据
    const allDoctors = await db.collection('doctors').find({}).toArray();
    console.log(`📊 总医生数量: ${allDoctors.length}`);
    
    // 按分类统计
    const categoryCount = {};
    allDoctors.forEach(doctor => {
      const category = doctor.category || '未分类';
      categoryCount[category] = (categoryCount[category] || 0) + 1;
    });
    
    console.log('\n📋 按分类统计:');
    Object.entries(categoryCount).forEach(([category, count]) => {
      console.log(`  ${category}: ${count} 条`);
    });
    
    // 显示前5个医生的基本信息
    console.log('\n👨‍⚕️ 前5个医生信息:');
    allDoctors.slice(0, 5).forEach((doctor, index) => {
      console.log(`  ${index + 1}. ${doctor.name} - ${doctor.hospital} - ${doctor.category}`);
    });
    
    // 检查是否有重复的医生ID
    const doctorIds = allDoctors.map(d => d.id || d._id);
    const uniqueIds = new Set(doctorIds);
    console.log(`\n🔍 ID重复检查: ${doctorIds.length} 个ID中有 ${uniqueIds.size} 个唯一ID`);
    
    if (doctorIds.length !== uniqueIds.size) {
      console.log('⚠️  发现重复的医生ID！');
      const duplicates = doctorIds.filter((id, index) => doctorIds.indexOf(id) !== index);
      console.log('重复的ID:', [...new Set(duplicates)]);
    }
    
  } catch (error) {
    console.error('❌ 检查失败:', error);
  } finally {
    await client.close();
  }
}

checkDoctorCount();
